home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / lut / powertbl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  2.2 KB  |  101 lines

  1. /*    Copyright (c) 1989 Michael Landy
  2.  
  3. Disclaimer:  No guarantees of performance accompany this software,
  4. nor is any responsibility assumed on the part of the authors.  All the
  5. software has been tested extensively and every effort has been made to
  6. insure its reliability.   */
  7.  
  8. /*
  9.  * powertbl.c - raise to a power and normalize each pixel of a frame.
  10.  *
  11.  * usage: powertbl [power] < frame > table_name
  12.  *
  13.  * default power:  .5
  14.  *
  15.  * For byte images, pixels are renormalized to lie between 0 and 255.  For
  16.  * short, integer, and float images, the output is a float image and no
  17.  * renormalization is performed.
  18.  *
  19.  * to load: cc -o powertbl powertbl.c -lhips -lm
  20.  *
  21.  * Yoav Cohen 2/16/82
  22.  * added int/float - Mike Landy - 3/16/89
  23.  *
  24.  *  modified to use look-up table for byte and short images:
  25.  *     Brian Tierney, LBL 10/90
  26.  *
  27.  *  modified to generate look-up table for any type of image, but not
  28.  *  apply the table to the image.  Therefore, this is to be used in
  29.  *  conjunction with mapapply to generate an image:
  30.  *     Bryan Skene, LBL 1/29/91
  31.  *
  32.  */
  33.  
  34. #include <hipl_format.h>
  35. #include <math.h>
  36. #include <stdio.h>
  37.  
  38.  
  39. #define MAXSHORT  32768
  40.  
  41. main(argc, argv)
  42.     int       argc;
  43.     char     *argv[];
  44.  
  45. {
  46.     double    power;
  47.     struct header hd;
  48.     int       form;
  49.  
  50.     Progname = strsave(*argv);
  51.     if (argc == 1 || argv[1][0] == '-')
  52.     power = .5;
  53.     else
  54.     power = atof(argv[1]);
  55.     read_header(&hd);
  56.     form = hd.pixel_format;
  57.     switch (form) {
  58.     case PFBYTE:
  59.     printf("256\n");
  60.     printf("%d\n", form);
  61.     make_byte_lut(power);
  62.     break;
  63.     case PFSHORT:
  64.     printf("32768\n");
  65.     form = PFFLOAT;
  66.     printf("%d\n", form);
  67.     make_short_lut(power);
  68.     break;
  69.     default:
  70.     perr(HE_MSG, "input format must be byte or short");
  71.     }
  72.     return (0);
  73. }
  74.  
  75. make_byte_lut(power)
  76.     double    power;
  77.  
  78. {
  79.     int       i;
  80.     unsigned char entry;
  81.  
  82.     for (i = 0; i < 256; i++) {    /* re-normalize to 0 to 255 */
  83.     entry = (unsigned char)
  84.         (255. * (pow((double) (i & 0377) / 255., power)) + 0.5);
  85.     printf("%d\n", entry);
  86.     }
  87. }
  88.  
  89. make_short_lut(power)
  90.     double    power;
  91.  
  92. {
  93.     int       i;
  94.     float     entry;
  95.  
  96.     for (i = 0; i < MAXSHORT; i++) {
  97.     entry = (float) (pow((double) i, power));
  98.     printf("%f\n", entry);
  99.     }
  100. }
  101.